#ifndef H_Point
#define H_Point
#include <iostream>
#include <list>
#include "Faces.h"

using namespace std;

class Face;


class Point{
  double x , y , z;
  int flag;
  list<Face*> faces;

 public:
  Point(){
    x = 0 ; y = 0 ; z = 0;
    flag = 0;
  }

  Point(double _x , double _y , double _z , int _flag = 0){
    x = _x; y = _y ; z = _z;
    flag = _flag;
  }

  void addFace(Face &f){
    faces.push_back(&f);
    ordonneFace();
  }

  void  ordonneFace(){

}
/*
	list<Point*> voisin;
	for(list<Face*>::iterator it = faces.begin() ; it != faces.end() ; it++){
		if((*it)->u != this && !contains((*it)->u , voisin))
			voisin.push_back((*it)->u);
		if((*it)->v != this && !contains((*it)->v , voisin))
			voisin.push_back((*it)->v);
		if((*it)->w != this && !contains((*it)->w , voisin))
			voisin.push_back((*it)->w);
	}	
	if(voisin.size() != faces.size()) return;
	else{
		list<Face*> _faces;
		_faces.push_back(faces.front());
		faces.pop_front();
		for(int i = 0 ; i < faces.size() ; i++){

			list<Face*>::iterator it = faces.begin();
			while(it != faces.end() && !shareVertex(*it , _faces.last()))
				it++;
			if(it != faces.end())
				_faces.push_back(*it);

		}

		faces = _faces;
	}
  }

  bool contains(Point* v , list<Point*> voisin){
	for(list<Point*>::iterator it = voisin.begin() ; it != voisin.end() ; it++)
		if(*it == v) return true;
	return false;
  }

  bool shareVertex(Face* f1 , Face* f2){
	if(*(f2->u) != *this && (*(f1->u) == *(f2->u) ||*(f1->v) == *(f2->u) || *(f1->w) == *(f2->u))) return true;
	if(*(f2->v) != *this && (*(f1->u) == *(f2->v) ||*(f1->v) == *(f2->v) || *(f1->w) == *(f2->v))) return true;
	if(*(f2->w) != *this && (*(f1->u) == *(f2->w) ||*(f1->v) == *(f2->w) || *(f1->w) == *(f2->w))) return true;
	return false;
  }*/

 void print(){
   cout <<  "( "<< x <<  " , "<< y <<  " , "<< z << " )";
  }

  void setX(double _x){
    x = _x;
  }

  void setY(double _y){
    y = _y;
  }
  void setZ(double _z){
    z = _z;
  }

  double getX(){
    return x;
  }

  double getY(){
    return y;
  }
  double getZ(){
    return z;
  }

};

#endif
